package com.xms.web.framework.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

/**
 * <p>
 * SpringWebInitializer
 * </p>
 *
 * @author migo
 * @since 2021/9/10
 */
@Configuration
@EnableWebMvc
public class SpringWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[] { SpringRootConfig.class };
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[] { SpringWebConfig.class };
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        /*FilterRegistration.Dynamic filter = servletContext.addFilter(CaseInsensitiveRequestParameterNameFilter.class.getSimpleName(),
                CaseInsensitiveRequestParameterNameFilter.class);
        filter.addMappingForUrlPatterns(null, true, "/*");*/
        servletContext.addListener(requestContextListener());

    }
    @Bean
    public CustomRequestContextListener requestContextListener(){
        return new CustomRequestContextListener();
    }
}